<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS定位-绝对定位</title>
    <style>
        /* ----------------------父级没有定位或者无父级的情况-------------------- */
        .father {
            width: 400px;
            height: 400px;
            background-color: gray;
        }

        .son {
            position: absolute;
            top: 80px;
            right: 250px;
            width: 250px;
            height: 250px;
            background-color: purple;

        }

        /* 当爷爷有定位的时候 */
        .box {
            position: relative;
            width: 800px;
            height: 800px;
            background-color: skyblue;

        }

        .box1 {
            width: 600px;
            height: 600px;
            background-color: purple;
        }
        .box2 {
            position: absolute;
            bottom: 100px;
            left: 200px;
            width: 300px;
            height: 300px;
            background-color: red;
        }

        /* ----------------------父级有定位的情况-------------------- */
    </style>
</head>

<body>
    <!-- ----------------------父级没有定位或者无父级的情况-------------------- -->
    <div class="father">
        <div class="son"></div>
    </div>
    <!-- ----------------------父级有定位的情况-------------------- -->
 <div class="box">
    <div class="box1">
        <div class="box2"></div>
    </div>
 </div>
</body>

</html>